package com.bbcare.oms.plat.controller;



import com.bbcare.oms.plat.service.IGuianSSOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

/**
 * 贵安sso处理器
 * author: liqianlong
 */
@Controller
@RequestMapping("/sso")
public class GuianSSOController {

    @Autowired
    private IGuianSSOService guianSSOService;


    //http://172.30.31.63:8001/oms/sso/index
    /**
     * 厂商调用贵安SSO登录
     * @param token 参数2：用户的Token
     * @param authkey 参数3：临时授权密钥base64
     * @param authEndTime 参数4：临时授权密钥base64
     * @param transactionId 参数5：授权操作事务流水号base64
     * @param request
     * @return 重定向自动登录页
     * @throws Exception
     */
    @GetMapping(value = "/index")
    public String handleTokenToIndex(
            @RequestParam("Token") String token,
            @RequestParam("AuthKEY") String authkey,
            @RequestParam("AuthEndTime") String authEndTime,
            @RequestParam("TransactionId") String transactionId,
            HttpServletRequest request) throws Exception {
        String username = guianSSOService.handleTokenToIndex(token,authkey,authEndTime,transactionId,request);
        return "redirect:/autoLogin.html?username=" + username;
    }

}
